//设置页面布局
var tabpanel;
var jcTabs = [
    '<iframe id="appliction_index"  src="./info.html" class="tabIframe" frameborder="no"  scrolling="yes" width="100%" height="100%"></iframe>'
];
var companyinfo = null;
$(function () {
    //页面布局显示
    $('body').layout({
        north__paneSelector: ".outer-north",
        center__paneSelector: ".outer-center",
        south__paneSelector: ".outer-south",
        west__paneSelector: ".outer-west",
        north__size: 80,
        //west__size: 101,
        south__size: 30,
        north__closable: false,
        west__closable: false,
        north__spacing_open: 0,
        south__closable: false,
        south__spacing_open: 0,
        west__spacing_open: 0,
    });
    tabpanel = new TabPanel({
        renderTo: 'index_tab',
        autoResizable: true,
        maxLength: 20,
        //border:'none',  
        active: 0,
        //maxLength : 10,  
        items: [{
            id: 'tab_index',
            title: '首页',
            html: jcTabs[0],
            closable: false
        }]
    });


    getCompany(function (company) {
        companyinfo = company;
        $('#conpanyName').text(companyinfo.name);
    });

    //绑定时钟
    showClock();

    //安全退出
    $("#logout").click(function () {
        ipcRenderer.send('logout', '');
    });

    //监听页面跳转的消息
    ipcRenderer.on('jupm-url', function (event, o) {
        addTabIframe(
            o.id,
            o.title,
            o.url)
    });

    //绑定点击事件
    $(".clickli").click(function () {
        addTabIframe(
            $(this).attr('id'),
            $(this).attr('title_'),
            $(this).attr('url_'))
    });

    //菜单的处理
    $(".close_all").click(function () {
        closeAllTabs();
    });

    $("#tab_index").bind('click', function () {
        $('#appliction_index').attr('src', $('#appliction_index').attr('src'));
    });

});

function closeAllTabs() {
    $.each($(".closer:not('.display_none')"), function () {
        $(this).click();
    });
    $('#appliction_index').attr('src', $('#appliction_index').attr('src'));
}

function addTabIframe(id, title, url) {
    if (url == null || url == '')
        return;
    tabpanel.addTab({
        id: "tab_" + id,
        title: title,
        html: '<iframe id="' + id + '" src="' + url + '" class="tabIframe" frameborder="no"  scrolling="no" width="100%" height="100%"></iframe>',
        closable: true
    });
}